<template>
  <div>
    <el-button type="primary" plain style="margin-bottom:10px;" @click="add">新增</el-button>
    <el-table :data="list" border height="471" style="width: 100%">
      <el-table-column type="index" width="50">
      </el-table-column>
      <el-table-column prop="title" label="类别">
      </el-table-column>
      <el-table-column prop="pidTitle" label="子类别">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="新增类别" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="类别名称">
          <el-input v-model="form.title" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="父类别">
          <el-select v-model="form.pid" placeholder="请选择">
            <el-option label="无" value="0"></el-option>
            <el-option v-for="(item,index) in pleibie" :key="index" :label="item.title" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapActions, mapMutations } = createNamespacedHelpers(
  "classify"
);
export default {
  name: "Classify",
  mounted() {
    this.getList();
  },
  data() {
    return {
      dialogFormVisible:false,
       form: {
          title: '',
          pid: '',
        },
    };
  },
  computed: {
    ...mapState(["list",'pleibie'])
  },
  methods: {
    add(){
      this.dialogFormVisible = true
    },
    save(){
      this.saveItem(this.form)
      this.dialogFormVisible = false
      this.form = {}
    },
    handleDelete(a, b) {
      if (!confirm("确定要删除嘛？")) {
        return;
      }
      this.del(b);
    },
    ...mapActions(["getList", "del",'saveItem'])
  }
};
</script>

<style>
</style>
